﻿CREATE PROCEDURE [ServiceEngine].[UpdateResource]
	@Name nvarchar(400),
	@Description ntext = null,	
	@InstanceID uniqueidentifier = null,
	@IDL nvarchar(max) = null,
	@IDLType nchar(100) = null,
	@BindingID uniqueidentifier,
	@Moniker xml = null,
	@RequestEntity uniqueidentifier = NULL,
	@ResponseEntity uniqueidentifier = NULL,
	@URI nvarchar(max) = NULL,
	@PolicyID uniqueidentifier = NULL,
	@ShareableProxy bit,
	@ID uniqueidentifier
AS
BEGIN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;
	SET NOCOUNT ON;

	BEGIN TRY
		BEGIN TRANSACTION

		UPDATE	ServiceEngine.Resources 
		SET		InstanceID = @InstanceID,
				IDL = @IDL,
				IDLType = @IDLType,
				BindingID = @BindingID,
				Moniker = @Moniker,
				RequestEntity = @RequestEntity,
				ResponseEntity = @ResponseEntity,
				URI = @URI,
				PolicyID = @PolicyID,
				ShareableProxy = @ShareableProxy
		WHERE	ResourceID = @ID

		UPDATE	ServiceEngine.Names
		SET		EntityName = @Name,
				EntityDescription = @Description
		WHERE	EntityID = @ID and EntityTypeID = 16

		COMMIT TRANSACTION
	END TRY
	BEGIN CATCH
		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;

		RAISERROR (@ErrorMessage, 
				   @ErrorSeverity,
				   1);
	END CATCH

END